/**
 * Copyright (c) 2006, geolabs
 * author : Gérald Fenoy
 *
 */

/**
 * PeriodicalRunner class
 *
 * This class is used to periodicaly launch function.
 *
 * @arg start int loop start 
 * @arg end int loop end
 * @arg freq int run function every freq secondes
 * @arg f function the function to launch
 * @arg step the value used to increment or decrement the loop index value
 *
 * @note You could use a start value gretter than the end value to excute the
 * loop in reverse mode (decrementing the loop interation value rather than
 * incrementing it).
 *
 */
PeriodicalRunner=Class.create({
  run: function(){
      var i=0;
      var test=(arguments[0].start>arguments[0].end);
      var tmp=(arguments[0].step?arguments[0].step:1);
      if(arguments[0].before)
	eval(arguments[0].before);
      for(var i=arguments[0].start;(test?i>=arguments[0].end:i<=arguments[0].end);(test?i-=tmp:i+=tmp)){
	setTimeout(arguments[0].f(i),(arguments[0].freq?arguments[0].freq:1000)*i);
	
      }
      if(arguments[0].after)
	eval(arguments[0].after);
    }
  });
